{% set host_index = groups[(inventory_hostname in groups['cinder']) | ternary('cinder', 'cinder_volume')].index(inventory_hostname) % groups['rabbitmq'] | count %}
{% set rabbit_hosts = groups['rabbitmq'][host_index:] + groups['rabbitmq'][:host_index] %}
[DEFAULT]

debug = {{ cinder_debug }}
use_stderr = False
use_syslog = {{ cinder_syslog_use }}
log_dir = /var/log/cinder

my_ip = {{ ip.mgmt }}
osapi_volume_listen = 127.0.0.1
osapi_volume_base_URL = {{ os_proto }}://{{ os_public_address }}:8776
public_endpoint = {{ os_proto }}://{{ os_public_address }}:8776
host = {{ inventory_hostname }}

rootwrap_config = /etc/cinder/rootwrap.conf
api_paste_confg = /etc/cinder/api-paste.ini
state_path = /var/lib/cinder
lock_path = /var/lock/cinder
volumes_dir = /var/lib/cinder/volumes
allow_availability_zone_fallback = True

auth_strategy = keystone
transport_url = rabbit://{% for host in rabbit_hosts %}{{ cinder_rabbit_user }}:{{ cinder_rabbit_password }}@{{ hostvars[host].ip.mgmt }}:5672{% if not loop.last %},{% endif %}{% endfor %}/{{ cinder_rabbit_vhost }}

glance_api_servers = {{ os_proto }}://{{ os_internal_address }}:9292
glance_api_insecure = {{ ssl_insecure }}
{% if SSLCACertificateFile != '' %}
glance_ca_certificates_file = {{ SSLCACertificateFile }}
{% endif %}

{% if inventory_hostname in groups['cinder_volume'] %}

{% if cinder_backends | count > 1 %}
enabled_backends = {% for backend in cinder_backends %}{{ backend.name }}{% if not loop.last %},{% endif %}{% endfor %}
{% endif %}

{% for backend in cinder_backends %}

{% if cinder_backends | count > 1 %}
[{{ backend.name }}]
{% endif %}

{% if backend.backend == 'lvm' %}

volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volume_group = cinder-volumes
iscsi_protocol = iscsi
iscsi_helper = tgtadm
volume_name_template = volume-%s
volume_group = cinder-volumes

{% elif backend.backend == 'ceph' %}

volume_driver=cinder.volume.drivers.rbd.RBDDriver
backup_driver=cinder.backup.drivers.ceph
rbd_cluster_name = {{ backend.ceph_cluster_name }}
rbd_ceph_conf = /etc/ceph/{{ backend.ceph_cluster_name }}.conf
rbd_pool = {{ backend.ceph_pool }}
rbd_user = {{ backend.ceph_user }}
rbd_secret_uuid = {{ backend.volume_secret_uuid }}
backup_ceph_conf = /etc/ceph/{{ backend.ceph_cluster_name }}.conf
backup_ceph_pool = {{ backend.backup_ceph_pool }}
backup_ceph_user = {{ backend.backup_ceph_user }}

{% endif %}
{% if cinder_backends | count > 1 %}
volume_backend_name = {{ backend.name }}
{% endif %}

{% endfor %}

{% endif %}

{% if groups['zookeeper'] | count > 0 %}
[coordination]
backend_url = kazoo://{% for host in groups['zookeeper'] %}{{ hostvars[host].ip.mgmt }}:2181{% if not loop.last %},{% endif %}{% endfor %}
{% endif %}


[database]
connection = mysql+pymysql://{{ cinder_db_user }}:{{ cinder_db_password }}@{{ cinder_mysql_server }}/{{ cinder_db }}?charset=utf8
max_retries = -1


[keymgr]
encryption_auth_url = {{ keystone_proto }}://{{ keystone_internal_address }}:5000/v3


[keystone_authtoken]
insecure = {{ ssl_insecure }}
{% if SSLCACertificateFile != '' %}
cafile = {{ SSLCACertificateFile }}
{% endif %}
auth_type = password
signing_dir = /var/lib/cinder/cache
auth_uri = {{ keystone_proto }}://{{ keystone_internal_address }}:5000
auth_url = {{ keystone_proto }}://{{ keystone_internal_address }}:35357
region_name = {{ keystone_region_name }}
user_domain_name = {{ cinder_domain_name }}
username = {{ cinder_admin_user }}
password = {{ cinder_admin_password }}
project_domain_name = {{ cinder_project_domain_name }}
project_name = {{ cinder_project_name }}

memcached_servers = {% for host in groups['memcached'] %}{{ hostvars[host].ip.mgmt }}:11211{% if not loop.last %},{% endif %}{% endfor %}

memcache_security_strategy = ENCRYPT
memcache_secret_key = {{ memcache_secret_key }}


[oslo_concurrency]
lock_path = /var/lock/cinder


[oslo_messaging_notifications]

driver = messagingv2
transport_url = rabbit://{% for host in rabbit_hosts %}{{ cinder_rabbit_user }}:{{ cinder_rabbit_password }}@{{ hostvars[host].ip.mgmt }}:5672{% if not loop.last %},{% endif %}{% endfor %}/{{ cinder_rabbit_vhost }}


[oslo_messaging_rabbit]
rabbit_ha_queues = true
